package errno

import (
	"context"
	"github.com/cloudwego/hertz/pkg/app"
	"net/http"
)

type Response struct {
	Code    int         `json:"code"`
	Result  interface{} `json:"result"`
	Message string      `json:"message"`
	TraceId any         `json:"trace_id"`
}

// 10006	操作权限不足

func Result(code int, data interface{}, msg string, ctx context.Context, c *app.RequestContext) {
	// 开始时间
	c.JSON(http.StatusOK, Response{
		code,
		data,
		msg,
		ctx.Value("trace_id"),
	})
}

func Ok(data interface{}, message string, ctx context.Context, c *app.RequestContext) {
	if len(message) == 0 {
		message = "success"
	}
	Result(SUCCESS, data, message, ctx, c)
}

func Fail(code int, data interface{}, message string, ctx context.Context, c *app.RequestContext) {
	if len(message) == 0 {
		message = "fail"
	}
	Result(code, data, message, ctx, c)
}
